package com.kotasoft.training.roogwteclipselink.client.managed.ui;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Element;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.Widget;


import com.kotasoft.training.roogwteclipselink.client.scaffold.place.ProxyDetailsView;
import com.kotasoft.training.roogwteclipselink.client.managed.request.AlumnoProxy;
import com.kotasoft.training.roogwteclipselink.client.managed.request.DireccionProxy;

/**
 * Details view for Alumno proxys.
 */
public class AlumnoMobileDetailsView extends Composite implements ProxyDetailsView<AlumnoProxy> {
	interface Binder extends UiBinder<HTMLPanel, AlumnoMobileDetailsView> {}

	private static final Binder BINDER = GWT.create(Binder.class);

	private static AlumnoMobileDetailsView instance;

	public static AlumnoMobileDetailsView instance() {
		if (instance == null) {
			instance = new AlumnoMobileDetailsView();
		}
		return instance;
	}

	AlumnoProxy proxy;
	
	@UiField Element id;
	@UiField Element version;
	@UiField Element nombre;
	@UiField Element apellidos;
	@UiField Element email;
	@UiField Element web;
	@UiField Element telefono;
	@UiField Element dni;
	@UiField Element direccion;	
	@UiField HasClickHandlers delete;

	private Delegate delegate;

	public AlumnoMobileDetailsView() {
		initWidget(BINDER.createAndBindUi(this));
	}

  	public Widget asWidget() {
		return this;
	}
  
	public boolean confirm(String msg) {
		return Window.confirm(msg);
	}

	public AlumnoProxy getValue() {
		return proxy;
	}

	@UiHandler("delete")
	public void onDeleteClicked(ClickEvent e) {
		delegate.deleteClicked();
	}

	public void setDelegate(Delegate delegate) {
		this.delegate = delegate;
	}

	public void setValue(AlumnoProxy proxy) {
		this.proxy = proxy;
		id.setInnerText(proxy.getId() == null ? "" : String.valueOf(proxy.getId()));
		version.setInnerText(proxy.getVersion() == null ? "" : String.valueOf(proxy.getVersion()));
		nombre.setInnerText(proxy.getNombre() == null ? "" : String.valueOf(proxy.getNombre()));
		apellidos.setInnerText(proxy.getApellidos() == null ? "" : String.valueOf(proxy.getApellidos()));
		email.setInnerText(proxy.getEmail() == null ? "" : String.valueOf(proxy.getEmail()));
		web.setInnerText(proxy.getWeb() == null ? "" : String.valueOf(proxy.getWeb()));
		telefono.setInnerText(proxy.getTelefono() == null ? "" : String.valueOf(proxy.getTelefono()));
		dni.setInnerText(proxy.getDni() == null ? "" : String.valueOf(proxy.getDni()));
		direccion.setInnerText(proxy.getDireccion() == null ? "" : com.kotasoft.training.roogwteclipselink.client.managed.ui.DireccionProxyRenderer.instance().render(proxy.getDireccion()));
	}
}
